<template>
  <div id="qrCode">
    <canvas id="canvas"></canvas>
    <p class="tip">Android扫码下载</p>
  </div>
</template>
<script>
import QRCode from 'qrcode'
export default {
  components: {
    QRCode: QRCode,
  },
  name: 'QRcode',
  props: {
    url: {
      type: String,
    },
  },
  data() {
    return {
      msg: 'hello vue',
      codes: '',
    }
  },

  methods: {
    useqrcode() {
      var canvas = document.getElementById('canvas')
      QRCode.toCanvas(canvas, this.url, function (error) {
        if (error) console.error(error)
      })
      //  new QRCode('qrcode', {
      //     text:this.url,
      //     correctLevel :3 //容错级别，默认为2，最高为3，为了让用户扫码最快，容错级别应当设为最低
      // });
    },
  },

  mounted() {
    this.useqrcode()
  },
}
</script>
<style lang="less" scoped>
#qrCode {
  text-align: center;
  position: absolute;
  top: 65px;
  line-height: 0;
  background: #fff;
  .tip {
    color: #000;
    position: relative;
    height: 22px;
  }
}
</style>
